{{Extend "layout"}}
{{Block "title"}}{{"评论列表"|T}}{{if Stored.data}} - {{Stored.data.Title}}{{end}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
<li><a href="__BACKEND__/official/news_index">{{"资讯列表"|T}}</a></li>
{{if Stored.data}}
<li><a href="__BACKEND__/official/news_edit?id={{Stored.data.Id}}" data-toggle="tooltip" title="{{"点击编辑"|T}}">{{Stored.data.Title|Default (T "无标题")}}</a></li>
{{end}}
<li class="active">{{"评论列表"|T}}</li>
{{/Block}}
{{Block "head"}}
<link rel="stylesheet" href="__ASSETS__/js/bootstrap.summernote/summernote.css?t={{BuildTime}}" type="text/css" />
{{/Block}}
{{Block "main"}}
<style>
.padding-x-15{padding-left:15px;padding-right:15px;}
</style>
{{if Stored.data}}
<div class="row">
    <div class="col-md-12">
        <div class="block-flat no-margin-y">
            <span class="label label-default">{{"评论对象"|T}}</span>
            <a style="font-weight:bold;font-size:18px" href="__FRONTEND__/news/detail/{{Stored.data.Id}}" target="_blank" data-toggle="tooltip" title="{{"点击打开详情页面"|T}}">
                {{Stored.data.Title|Default (T "无标题")}}
            </a>
            <i class="fa fa-share-square grey"></i>
        </div>
    </div>
</div>
{{end}}
{{$unixtime:=UnixTime}}
<div class="row">
    <div class="col-md-12">
        <div class="block-transparent">
          <div class="header" style="height:40px;line-height:30px;">
            <span class="pull-right">
                <form class="form-horizontal" action="" id="search-form" method="GET">
                    <input type="hidden" name="targetId" value="{{Form "targetId"}}">
                    <input type="hidden" name="targetType" value="{{Form "targetType"}}">
					<div class="input-group">{{$display := Form "display"}}
						<span class="input-group-addon">{{"状态"|T}}</span>
						<select name="display" class="form-control" id="display" onchange="$('#search-form').submit()">
							<option value=""> - {{"不限"|T}} - </option>
							<option value="Y" {{if eq $display "Y"}} selected{{end}}>{{"显示"|T}}</option>
							<option value="N" {{if eq $display "N"}} selected{{end}}>{{"隐藏"|T}}</option>
						</select>
					</div>
				</form>
            </span>
            <h4>{{"评论列表"|T}}</h4>
          </div>
          <div id="comment-list-container">
              {{Include "official/comment_list_partial"}}
        </div><!-- #comment-list-container -->
        </div>
    </div>
</div>
<div class="row"{{if not Stored.data}} style="display:none;"{{end}}>
    <div class="col-md-12">
        <div class="block-flat">
            <div class="header">
                <h3>{{"发表评论"|T}}</h3>
            </div>
            <div class="content">
                <form class="form-horizontal group-border-dashed" action="__BACKEND__/official/comment_add" id="comment-form" novalidate>{{$targetType := Form "targetType"}}
                    <div class="form-group" id="comment-form-input-container">
                        <textarea id="content" name="content" action="__BACKEND__/manager/upload/comment?refid=0&time={{$unixtime}}&token={{Token "refid" 0 "time" $unixtime}}" required></textarea>
                        <input type="hidden" name="replyId" id="reply-id" value="0">
                        <input type="hidden" name="targetType" id="target-type" value="{{$targetType}}">
                        <input type="hidden" name="targetId" id="target-id" value="
                        {{if Stored.data}}{{Stored.data.Id}}{{end}}">
                        <input type="hidden" name="contype" value="html">
                    </div>
                    <div class="form-group">
                        <div class="col-sm-12">
                          <button type="submit" class="btn btn-primary">{{"发表评论"|T}}</button>
                          <button class="btn btn-default">{{"取消"|T}}</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{{/Block}}
{{Block "footer"}}
{{Modal "__TMPL__/official/comment_form.yaml"}}
<script src="__ASSETS__/js/bootstrap.summernote/summernote.min.js?t={{BuildTime}}"></script>
<script src="__ASSETS__/js/bootstrap.summernote/lang/summernote-zh-CN.js?t={{BuildTime}}"></script>
<script src="__ASSETS__/js/behaviour/page/summernote.min.js?t={{BuildTime}}"></script>
<script src="__ASSETS__/js/bootstrap.switch/bootstrap-switch.min.js?t={{BuildTime}}"></script>
<!-- markdown support -->
<script type="text/javascript" src="__ASSETS__/js/markdown/it/markdown-it.min.js?t={{BuildTime}}"></script>
<script type="text/javascript" src="__ASSETS__/js/markdown/it/plugins/emoji/markdown-it-emoji.min.js?t={{BuildTime}}"></script>
<script type="text/javascript" src="__ASSETS__/js/markdown/it/plugins/highlight/loader/prettify.js?t={{BuildTime}}"></script>
<script type="text/javascript" src="__ASSETS__/js/markdown/it/plugins/highlight/loader/run_prettify.js?t={{BuildTime}}&skin=sons-of-obsidian"></script>
<script type="text/javascript" src="__ASSETS__/js/markdown/it/common.js?t={{BuildTime}}"></script>
<!-- /markdown support -->
<script type="text/javascript">
var LANG_REPLY_SUCCESS='{{"回复成功"|T}}';
var LANG_OP_SUCCESS='{{"操作成功"|T}}';
var LANG_RM_SUCCESS='{{"删除成功"|T}}';
var LANG_COMMENT_SUCCESS='{{"评论成功"|T}}';
var LANG_RM_CONFIRM='{{"确认要删除吗？一旦删除将会同时删除该评论下的所有回复，并且不可恢复。"|T}}';
function showCommentFormModal(){
    $('#modal-comment-form').niftyModal('show');
}
function attachPostReplyModal(){
$('#modal-comment-form .modal-footer .btn-primary').on('click',function(e){
    e.preventDefault();
    var $form=$('#modal-comment-form-container');
    $.post(BACKEND_URL+'/official/comment_add',$form.serializeArray(),function(r){
        if(r.Code>0){
            $('#modal-comment-content').summernote('code', '');
            commentLoadList();
        }
        App.message({text:r.Code>0?LANG_REPLY_SUCCESS:r.Info,class_name:r.Code>0?'success':'error'});
    },'json');
});
}
function initCommentFormModal(){
    var h=$(window).height()-200;
    $('#modal-comment-form').find('.modal-body').css({"height":h});
    var a=$('#comment-form-input-container').clone();
    a.find('#content').attr('id','modal-comment-content');
    a.find('#reply-id').attr('id','modal-comment-reply-id');
    a.find('#target-id').attr('id','modal-comment-target-id');
    a.find('#target-type').attr('id','modal-comment-target-type');
    $('#modal-comment-form-input-container').html(a.html());
    var eh=h-160;
    summernoteEditor('#modal-comment-content',eh>100?eh:100);
    attachPostReplyModal();
}
function commentReply(a){
    $('#modal-comment-reply-id').val($(a).data('comment-id'));
    $('#modal-comment-target-id').val($(a).data('target-id'));
    $('#modal-comment-target-type').val($(a).data('target-type'));
    showCommentFormModal();
}
function commentRemove(a){
    if(!confirm(LANG_RM_CONFIRM))return;
    $.get(BACKEND_URL+'/official/comment_delete',{id:$(a).data('comment-id')},function(r){
        App.message({text:r.Code>0?LANG_RM_SUCCESS:r.Info,class_name:r.Code>0?'success':'error'});
        if(r.Code<1){
            return;
        }
        commentLoadList();
    },'json');
}
function commentDisplay(a){
    $.get(BACKEND_URL+'/official/comment_edit',{id:$(a).data('comment-id'),display:$(a).is(':checked')?'Y':'N'},function(r){
        App.message({text:r.Code>0?LANG_OP_SUCCESS:r.Info,class_name:r.Code>0?'success':'error'});
        if(r.Code<1){
            return;
        }
    },'json');
}
function commentLoadList(){
    $.get(window.location.href,{partial:1},function(r){
        var box=$('#comment-list-container');
        box.html(r);
        if(typeof(window.markdownParse)!='undefined'){
            markdownParse(box);
        }
        box.find('.switch').bootstrapSwitch();
    },'html');
}
$(function(){
initCommentFormModal();
summernoteEditor('#content',100);
$('#comment-form').on('submit',function(e){
    e.preventDefault();
    var $form=$(this);
    $.post($(this).attr('action'),$(this).serializeArray(),function(r){
        if(r.Code>0){
            $('#content').summernote('code', '');
            commentLoadList();
        }
        App.message({text:r.Code>0?LANG_COMMENT_SUCCESS:r.Info,class_name:r.Code>0?'success':'error'});
    },'json');
});
    var box=$('#comment-list-container');
    if(typeof(window.markdownParse)!='undefined'){
        markdownParse(box);
    }
});
</script>
{{/Block}}